package com.db.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * @author Xiongx
 * @version 1.0
 * @date 2021/4/21 9:24
 * @since JDK 1.8
 * 数据库连接
 */
public class Connectionzz {

    private static final Logger log=LoggerFactory.getLogger(Connectionzz.class);

    private Connection conn = null;

    public Connection createConnection(String driver,String url,String username,String password){
        try{
            log.info("开始连接====>");
            //获取连接对象Connection
            Class.forName(driver);
            conn = DriverManager.getConnection(url,username,password);
        }catch (ClassNotFoundException e) {
            e.printStackTrace();
        }catch (SQLException e){
            e.printStackTrace();
        }
        return conn;
    }

    private void close(){
        try{
            conn.close();
        }catch (SQLException e){
            e.printStackTrace();
        }
    }
}
